import axios from 'axios'

export default {
  namespaced: true,

  state: () => ({
    token: '',
    userInfo: {},
    Menus: {}
  }),
  mutations: {
    updateToken (state, token) {
      state.token = token
    },
    updateUserInfo (state, userInfo) {
      state.userInfo = userInfo
    },
    updateMenus (state, menus) {
      state.Menus = menus
    }
  },
  actions: {
    async getUserInfo (ctx) {
      const { data: res } = await axios.get('/my/userinfo').catch(e => e)
      //   console.log(ctx)
      if (res.code !== 0) return
      ctx.commit('updateUserInfo', res.data)
    },
    async getMenus (ctx) {
      const { data: res } = await axios.get('/my/menus')
      // console.log(res)
      if (res.code !== 0) return
      ctx.commit('updateMenus', res.data)
    }
  }
}
